
import { ref, computed, onMounted, onUnmounted, unref } from "vue"
import pubsub from "pubsub-js"

interface Options {
  topic: string
}
export function useEventBus(opt: Options, callback?: (data: any) => void) {
  onMounted(() => {
    console.log('订阅事件, topic: ', opt.topic)
    pubsub.subscribe(opt.topic, (msg, data) => {
      console.log('接收订阅事件, data: ', data)
      callback && callback(data)
    })
  })

  onUnmounted(() => {
    console.log('取消订阅事件, topic: ', opt.topic)
    pubsub.unsubscribe(opt.topic)
  })
  return {
    
  }
}
